<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串类型</title>
    <script>
        function f1() {
            let s = " Hello World ";
            console.log("字符串长度:" + s.length)
            // 去除字符串首尾的空格
            s = s.trim();
            console.log("字符串长度:" + s.length)
            console.log(s.toUpperCase())
            console.log(s.toLowerCase())
            console.log(s.charAt(8))
            console.log(s.substring(6))
            console.log(s.substring(0, 5))
            s = "admin tom jack admin alice admin";
            console.log(s.indexOf("admin"))
            console.log(s.length)
            console.log(s.lastIndexOf("admin"))
            console.log(s.replace(" ", "-"))
        }

        function f2() {
            // let s = "123";
            // let s = "123.45";
            // let s = "123ab";
            // let s = "a123";
            let s = "123ab45";
            s = parseInt(s);
            console.log(s);
        }

        function f3() {
            // let s = "123";
            // let s = "123.45";
            // let s = "123.";
            // let s = "123.45.67";
            // let s = "123.4a5";
            let s = "a123.45";
            s = parseFloat(s);
            console.log(s);
        }
    </script>
</head>
<body>
<button onclick="f1()">测试</button>
<br>
<button onclick="f2()">转换整数</button>
<br>
<button onclick="f3()">转换浮点数</button>
</body>
</html>